﻿@model GroupEditModel
@{
    Layout = "app-1col";
    int groupName = Model.GroupName == null ? 0 : Model.GroupName.Length;
}
@section ContentHeader{
    @Html.Action("_GroupSubmenu", "ChannelGroup")
}
@Html.StatusMessage()
<div class="tn-box tn-widget tn-widget-content tn-corner-all spb-group-edit">
    <div class="tn-box-content tn-widget-content tn-corner-all">
        <div class="tn-main-heading tn-border-gray tn-border-bottom">
            <h2>
                创建商户</h2>
        </div>
        @using (Html.BeginForm("Create", "ChannelGroup", FormMethod.Post, new { enctype = "MULTIPART/FORM-DATA", id = "form-group-create" }))
        {
            @Html.Hidden("GroupId", 0)
            <div class="tn-form-box">
                <table>
                    <tr class="tn-name">
                        <th>
                            <span class="tn-form-required">*</span>
                            用户名：
                        </th>
                        <td>
                            @Html.TextBoxFor(n => n.UserName, new { @class = "tn-textbox tn-border-gray" })
                        </td>
                        <td>
                            @Html.ValidationMessageFor(n => n.UserName)
                    </td>
                </tr>
                    <tr class="tn-name">
                        <th>
                            <span class="tn-form-required">*</span>
                            密码：
                        </th>
                        <td>
                            @Html.TextBoxFor(n => n.Password, new { @class = "tn-textbox tn-border-gray",@type="password" })
                        </td>
                        <td>
                            @Html.ValidationMessageFor(n => n.Password)
                        </td>
                    </tr>
                    <tr class="tn-name">
                        <th>
                            <span class="tn-form-required">*</span>
                            手机号：
                        </th>
                        <td>
                            @Html.TextBoxFor(n => n.AccountMobile, new { @class = "tn-textbox tn-border-gray" })
                        </td>
                        <td>
                            @Html.ValidationMessageFor(n => n.AccountMobile)
                        </td>
                    </tr>


                    <tr style="display:none">
                        <th>
                            商户类型：
                        </th>
                        <td>
                            <ul class="tn-radiobutton-list">
                                <li id="public">
                                    <label>
                                        @Html.RadioButton("IsPublic", true, true, new { group = "groupType", id = "isPublic" })
                                        公开 <span class="tn-text-note">信息公开，任何人可见，允许用户直接加入商户。</span>
                                    </label>
                                </li>
                                <li id="private">
                                    <label>
                                        @Html.RadioButton("IsPublic", false, false, new { group = "groupType", id = "isPrivate" })
                                        私密 <span class="tn-text-note">信息不公开，需管理审核或成员邀请才可以加入。</span>
                                    </label>
                                </li>
                            </ul>
                        </td>
                        <td>
                        </td>
                    </tr>

                    <tr class="tn-name">
                        <th>
                            <span class="tn-form-required">*</span>
                            名称：
                        </th>
                        <td>
                            @Html.TextBoxFor(n => n.GroupName, new { @class = "tn-textbox tn-border-gray" })
                            <span id="GroupNameCount" class="tn-count tn-text-note">@groupName/60</span>
                        </td>
                        <td>@Html.ValidationMessageFor(n => n.GroupName)
                        </td>
                    </tr>
                    <tr>
                        <th>
                            所属商户编号：
                        </th>
                        <td>
                            @Html.TextBoxFor(n => n.GroupByType, new { @class = "tn-textbox tn-border-gray" })
                        </td>
                        <td>@Html.ValidationMessageFor(n => n.GroupByType)</td>
                    </tr>
                    <tr class="tn-intro">
                        <th>
                            简介：
                        </th>
                        <td>
                            @Html.TextAreaFor(n => n.Description, new { @class = "tn-textarea tn-border-gray" })
                        </td>
                        <td>@Html.ValidationMessageFor(n => n.Description)
                        </td>
                    </tr>
                    <tr class="tn-url">
                        <th>
                            <span class="tn-form-required">*</span>
                            个性网址：
                        </th>
                        <td>
                            @{ string[] fullUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome("#")).Split('#');}
                            @if (fullUrl.Length == 2)
                            {
                                @fullUrl[0] 
                                @Html.TextBoxFor(n => n.GroupKey, new { @class = "tn-textbox tn-border-gray" })
                                @fullUrl[1]
                            }
                        </td>
                        <td>
                            @Html.ValidationMessageFor(n => n.GroupKey)
                        </td>
                    </tr>
                    <tr>
                        <th>
                            logo：
                        </th>
                        <td>
                            <input type="file" id="GroupLogo" name="GroupLogo" />
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span class="tn-form-required">*</span>
                            类别：
                        </th>
                        <td>@Html.CategoryDropDownListFor(n => n.CategoryId, TenantTypeIds.Instance().Group(), 0)
                        </td>
                        <td>@Html.ValidationMessageFor(n => n.CategoryId)
                        </td>
                    </tr>
                    <tr>
                        <th>
                            地区：
                        </th>
                        <td>@Html.AreaDropDownListFor(n => n.AreaCode, 3)
                        </td>
                        <td>@Html.ValidationMessageFor(n => n.AreaCode)
                        </td>
                    </tr>
                    <tr class="tn-name">
                        <th>
                            <span class="tn-form-required">*</span>
                            详细地址：
                        </th>
                        <td>
                            @Html.TextBoxFor(n => n.GroupAdress, new { @class = "tn-textbox tn-border-gray" })
                        </td>
                        <td>
                            @Html.ValidationMessageFor(n => n.GroupAdress)
                        </td>
                    </tr>
                    <tr style="display:none">
                        <th>
                            商户成员：
                        </th>
                        <td>
                            @Html.UserSelector("RelatedUserIds", 10, null, searchScope: UserSelectorSearchScope.FollowedUser, showDropDownMenu: true, widthType: SelectorWidthType.Longer)
                    </td>
                    <td></td>
                </tr>
                    <tr>
                        <th>
                            标签：
                        </th>
                        <td>@Html.TagSelector("RelatedTags", TenantTypeIds.Instance().Group(), Model.GroupId, Model.GroupId)
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr style="display:none">
                        <th>
                            加入方式：
                        </th>
                        <td>
                            <ul class="tn-radiobutton-list" id="joinwaylist">
                                <li id="direct" class="tn-inline-list">
                                    <label>@Html.RadioButton("JoinWay", JoinWay.Direct, true, new { group = "joinWay", id = "isDirect" })
                                        直接加入</label>
                                </li>
                                <li id="apply" class="tn-inline-list">
                                    <label>@Html.RadioButton("JoinWay", JoinWay.ByApply, false, new { group = "joinWay", id = "isApply" })
                                        申请加入</label>
                                </li>
                                <li id="invite" class="tn-inline-list">
                                    <label>@Html.RadioButton("JoinWay", JoinWay.ByInvite, false, new { group = "joinWay", id = "isInvite" })
                                        邀请加入</label>
                                </li>
                                <li id="question" class="tn-inline-list">
                                    <label>@Html.RadioButton("JoinWay", JoinWay.ByQuestion, false, new { group = "joinWay", id = "isQuestion" })
                                        问题验证</label>
                                </li>
                            </ul>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr style="display:none">
                        <th>
                        </th>
                        <td>
                            <div id="Direct" class="tn-widget tn-bubble tn-bubble-arrow-top spb-group-bubble spb-groupbubble-one"
                                 style="display: none">
                                <div class="tn-bubble-arrow">
                                    <b class="tn-arrow-b1 tn-border-gray"></b><b class="tn-arrow-b2 tn-bubble-gray">
                                    </b>
                                </div>
                                <div class="tn-bubble-content tn-border-gray tn-bg-gray tn-corner-all">
                                    <p>
                                        用户可以直接加入
                                    </p>
                                </div>
                            </div>
                            <div id="ByApply" class="tn-widget tn-bubble tn-bubble-arrow-top spb-group-bubble spb-groupbubble-two"
                                 style="display: none">
                                <div class="tn-bubble-arrow">
                                    <b class="tn-arrow-b1 tn-border-gray"></b><b class="tn-arrow-b2 tn-bubble-gray">
                                    </b>
                                </div>
                                <div class="tn-bubble-content tn-border-gray tn-bg-gray tn-corner-all">
                                    <p>
                                        用户需要管理员审核通过以后才能加入
                                    </p>
                                </div>
                            </div>
                            <div id="ByInvite" class="tn-widget tn-bubble tn-bubble-arrow-top spb-group-bubble spb-groupbubble-three"
                                 style="display: none">
                                <div class="tn-bubble-arrow">
                                    <b class="tn-arrow-b1 tn-border-gray"></b><b class="tn-arrow-b2 tn-bubble-gray">
                                    </b>
                                </div>
                                <div class="tn-bubble-content tn-border-gray tn-bg-gray tn-corner-all">
                                    <p>
                                        用户需要通过内部成员的邀请才能加入
                                    </p>
                                </div>
                            </div>
                            <div id="ByQuestion" class="tn-widget tn-bubble tn-bubble-arrow-top spb-group-bubble spb-groupbubble-four"
                                 style="display: none">
                                <div class="tn-bubble-arrow">
                                    <b class="tn-arrow-b1 tn-border-gray"></b><b class="tn-arrow-b2 tn-bubble-gray">
                                    </b>
                                </div>
                                <div class="tn-bubble-content tn-border-gray tn-bg-gray tn-corner-all">
                                    <p>
                                        您可以设置你一个问题，用户答对后即可加入
                                    </p>
                                    <p>
                                        问题：
                                        @Html.TextBoxFor(n => n.Question, new { @class = "tn-textbox tn-input-medium tn-border-gray", watermark = "如1+1=？" })
                                        @Html.ValidationMessageFor(n => n.Question)
                                    </p>
                                    <p>
                                        答案：
                                        @Html.TextBoxFor(n => n.Answer, new { @class = "tn-textbox tn-input-medium tn-border-gray" })
                                        @Html.ValidationMessageFor(n => n.Answer)
                                    </p>
                                </div>
                            </div>
                        </td>
                        <td></td>
                    </tr>
                    <tr style="display:none">
                        <th>
                            邀请权限：
                        </th>
                        <td>
                            <ul class="tn-radiobutton-list">
                                <li class="tn-inline-list">
                                    <label>@Html.RadioButton("EnableMemberInvite", true, true, new { group = "authority", id = "member" })
                                        所有成员</label>
                                </li>
                                <li class="tn-inline-list">
                                    <label>@Html.RadioButton("EnableMemberInvite", false, false, new { group = "authority", id = "admin" })
                                        仅管理员</label>
                                </li>
                            </ul>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <th>
                        </th>
                        <td>
                            @Html.Button("保存", buttonType: ButtonTypes.Submit, highlightStyle: HighlightStyles.Primary)
                            @if (Request.UrlReferrer != null)
                            {
                                @Html.Button("取消", buttonType: ButtonTypes.Button, highlightStyle: HighlightStyles.Secondary, url: Request.UrlReferrer.PathAndQuery)
                            }
                        </td>
                        <td>
                        </td>
                    </tr>
                </table>
            </div>
        }
    </div>
</div>
<script type="text/javascript">
    $(function () {
        //处理火狐下刷新后单选框和单选钮仍然选中问题
        if ($.browser.mozilla) {
            $("input[type='radio']").attr("autocomplete", "off");
            $("input[type='checkbox']").attr("autocomplete", "off");
        }
        var validatorSettings = $('form#form-group-create').data('validator').settings;
        validatorSettings.ignore = "input:hidden[type='text']";
        //获取填写的字数
        var form = $('form#form-group-create');
        $("#GroupName", form).GetTextCount('GroupNameCount', 60, true);
        $("#public").click();
        $("div.spb-group-bubble").eq(0).show();

        $("#private").click(function () {
            $("#isInvite").click();
            $("div#ByInvite").removeClass("spb-groupbubble-three").addClass("spb-groupbubble-one");
            $("#direct,#question,#apply").hide();
        });
        $("#public").click(function () {
            $("#isDirect").click();
            $("div#ByInvite").removeClass("spb-groupbubble-one").addClass("spb-groupbubble-three");
            $("#direct,#question,#apply").show();
        });
        $("div ul#joinwaylist li").click(function () {
            var index = $(this).index();
            $("div.spb-group-bubble").hide();
            $("div.spb-group-bubble").eq(index).show();
        });
    });
</script>
